package com.dxyxx.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dxyxx.R;

/**
 * 回调机制
 * 
 * @author Administrator
 * 
 */
public class AgainPlayer {
	public CallBack mc;
	private Context context;
 

	public AgainPlayer(Context context,   CallBack mc) {
		this.mc = mc;
		 
		this.context = context;
	}

	public void call(  final String info) {

		final DKDialog dialog = new DKDialog(context, R.style.MyDialog);
		dialog.setContentView(R.layout.common_alertdialog);

		dialog.show();
		TextView tv = (TextView) dialog.findViewById(R.id.tv_common_alerdialog_content);
		tv.setText("出问题了！！： " + info);
		/*
		 * 监听imgbtn关闭dialog
		 */
		ImageView customviewtvimgCancel = (ImageView) dialog.findViewById(R.id.customviewtvimgCancel);
		customviewtvimgCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		/*
		 * 监听btn 重试
		 */
		Button buttonSure = (Button) dialog.findViewById(R.id.b_sure);
		buttonSure.setText("重试");
		buttonSure.setOnTouchListener(new ViewTouchListener(context, buttonSure));
		buttonSure.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
				mc.method();
			}
		});
		/*
		 * 监听取消
		 */
		Button buttonCancel = (Button) dialog.findViewById(R.id.b_cancel);
		buttonCancel.setOnTouchListener(new ViewTouchListener(context, buttonCancel));
		buttonCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});

	}

	public static void makeCall(  Context context, final String info) {
		/*
		 * LayoutInflater inflater = activity.getLayoutInflater();
		 * AlertDialog.Builder builder = new AlertDialog.Builder(activity); View
		 * view = inflater.inflate(R.layout.common_alertdialog, null);
		 * builder.setView(view); final AlertDialog dialog = builder.show();
		 */
		final DKDialog dialog = new DKDialog(context, R.style.MyDialog);
		dialog.setContentView(R.layout.common_alertdialog);

		dialog.show();
		TextView tv = (TextView) dialog.findViewById(R.id.tv_common_alerdialog_content);
		tv.setText("出问题了！！： " + info);
		/*
		 * 监听imgbtn关闭dialog
		 */
		ImageView customviewtvimgCancel = (ImageView) dialog.findViewById(R.id.customviewtvimgCancel);
		customviewtvimgCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		/*
		 * 监听btn发邮件
		 */
		Button buttonSure = (Button) dialog.findViewById(R.id.b_sure);
		buttonSure.setOnTouchListener(new ViewTouchListener(context, buttonSure));
		buttonSure.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();

			}
		});
		/*
		 * 监听取消
		 */
		Button buttonCancel = (Button) dialog.findViewById(R.id.b_cancel);
		buttonCancel.setOnTouchListener(new ViewTouchListener(context, buttonCancel));
		buttonCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
	}

	public interface CallBack {
		public void method();
	}
}
